package com.sinog.front.controller.api;

import com.sinog.core.utilbean.Constants;
import com.sinog.core.utilbean.Result;
import com.sinog.front.feign.biz.api.xml.XmlMinitoringService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

/**
 * @desc 前置机上传zip包监听接口
 * @author lzq
 * @date 2022/6/27 13:58
 */
@Slf4j
@RestController
public class XmlMonitoringController {

    private static final SimpleDateFormat SIMPLEDATEFORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    @Autowired
    private XmlMinitoringService xmlMinitoringService;

    /**
     * 监听linux服务器发送来的zip包文件变更通知请求
     * @param zipName zip包文件名
     * @return String
     */
    @RequestMapping(value = "/transmission/api/azbj/xml/monitoring", method = RequestMethod.GET, produces = "application/json;charset=utf-8;")
    public String monitoring(@RequestParam String zipName) {
        log.info("前置机上传了一个zip包:"+zipName);
        xmlMinitoringService.monitoring(zipName);
        return SIMPLEDATEFORMAT.format(new Date()) + " : " + zipName + " : " + Constants.HnInterfaceDocking.SUCCESS;
    }

    /**
     * 0702B、0702HZ流程
     * @param hzParams map
     * @return String
     */
    @RequestMapping(value = "/transmission/api/azbj/xml/processOut", method = RequestMethod.POST, produces = "application/json;charset=utf-8;")
    public String processOut(@RequestBody Map<String, String> hzParams) {
        log.info("收到回执:"+hzParams);
        Result processOut = xmlMinitoringService.processOut(hzParams);
        return SIMPLEDATEFORMAT.format(new Date()) + " : " + processOut + " : " + Constants.HnInterfaceDocking.SUCCESS;
    }
}